// 该模块为创建和判断effect提供支持

/** effect对象标识 */
const identification = '@@Redux-saga/IO'

/**
 * effect 可用类型
 */
export const effectTypes = {
    ALL: "ALL",
    CALL: "CALL",
    APPLY: "APPLY",
    TAKE: "TAKE",
    TAKELATEST: "TAKELATEST",
    DELAY2: "DELAY2",
    PUT: "PUT",
    SELECT: "SELECT",
    FORK: "FORK",
    RACE: "RACE",
    CANCEL: "CANCEL",
    CANCELLED: "CANCELLED",
    CPS: "CPS",
}

/**
 * 创建effect  
 * @export
 * @param {*} type effect类型
 * @param {*} payload
 * @return {*} 返回一个effect对象
 */
export function craeteEffect(type, payload) {
    const includes = Object.values(effectTypes).includes(type)
    if (!includes) {
        throw new TypeError(`${type} 是一个无效的type值`)
    }
    return {
        [identification]: true,
        type,
        payload
    }
}


/**
 * 判断一个对象是否effect对象
 * @export
 * @param {object} obj
 * @return {boolean}
 */
export function isEffect(obj) {
    if (typeof obj !== 'object' || obj === null) return false
    return obj[identification]
}